package com.yy.market.mvp.adapter;

import android.content.Context;
import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yy.market.R;
import com.yy.market.mvp.bean.HomeTypeButton;
import com.yy.market.utils.ListUtils;

import java.util.List;

/**
 * Created by luweibin on 2016/8/17.
 */
public class Home10BtnAdapter extends RecyclerView.Adapter {
    Context context;
    List<HomeTypeButton> homeTypeButtons;

    public Home10BtnAdapter(Context context, List<HomeTypeButton> homeTypeButtons) {
        this.context = context;
        this.homeTypeButtons = homeTypeButtons;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.home_item_10_button_item, parent, false);
        return new ButtonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        HomeTypeButton homeTypeButton = homeTypeButtons.get(position);
        ButtonViewHolder buttonViewHolder = (ButtonViewHolder) holder;
        buttonViewHolder.imageView.setBackgroundResource(homeTypeButton.getButtonImage());
        buttonViewHolder.textView.setText(homeTypeButton.getButtonTitle());
    }

    @Override
    public int getItemCount() {
        return ListUtils.getSize(homeTypeButtons);
    }

    static class ButtonViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView textView;
        public ButtonViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.home_btn_imageView);
            textView = (TextView) itemView.findViewById(R.id.home_btn_textView);
        }
    }
}
